<!DOCTYPE html>
<html>
<head>
    <title>Strategy Pattern</title>
    <script>
        var FlyBehavior = function () {
        };
        FlyBehavior.prototype.fly = function () {
        };

        var FlyWithWings = function () {
        };
        FlyWithWings.prototype = new FlyBehavior();
        FlyWithWings.prototype.fly = function () {
            console.log('i fly with wings');
        };

        var FlyNoWay = function () {
        };
        FlyNoWay.prototype = new FlyBehavior();
        FlyNoWay.prototype.fly = function () {
            console.log('i can not fly');
        };

        document.addEventListener('DOMContentLoaded', function () {
            var Duck = function () {
            };
            Duck.prototype = {
                /**
                 * @type FlyBehavior
                 */
                flyBehavior: null,
                quackBehavior: null,
                swim: function () {
                },
                display: function () {
                    console.log('i am a duck');
                },
                quack: function () {
                },
                fly: function () {
                    this.flyBehavior.fly();
                }
            };

            var RedheadDuck = function () {
                this.flyBehavior = new FlyWithWings();
            };
            RedheadDuck.prototype = new Duck();
            RedheadDuck.prototype.display = function () {
                console.log('i am a redhead duck');
            };

            var RubberDuck = function () {
                this.flyBehavior = new FlyNoWay();
            };
            RubberDuck.prototype = new Duck();
            RubberDuck.prototype.display = function () {
                console.log('i am a rubber duck');
            };

            //test
            var duck = new Duck();
            duck.display();
            var redheadDuck = new RedheadDuck();
            redheadDuck.display();
            redheadDuck.fly();
            var rubberDuck = new RubberDuck();
            rubberDuck.display();
            rubberDuck.fly();
        });
    </script>
</head>
<body>

</body>
</html>